package practice;

public class CarPactice {
    /**
     * 用于显示车的外观
     */
    private String name;//车的品牌
    private int width;//车的宽度
    private int height;//车的高度
    private int length;//车的长度
    /**
     *用于获取当前车的位置
     */
    private double x;//当前位置的x坐标
    private double y;//当前位置的y坐标
    /**
     * 来获取当前剩余燃料
     */
    private double fuel;//剩余燃料
    private double fuelCost=5.0;//每公里燃料费用
    private double s=0.0;//总费用
    private double total;//一次移动的费用



    public CarPactice(String name,int width,int height,int length,double fuel){
        this.name=name;

        this.width=width;
        this.height=height;
        this.length=length;
        this.fuel=fuel;
        x=y=0.0;

    }

    //获取当前小车的坐标
    double getX(){return x ;}
    double getY(){return y;}
    double getFuel(){return fuel;}

    //向x方向,向Y方向移动
   public boolean move(double dx,double dy){
        double dist=Math.sqrt(dx*dx+dy*dy);
        if (dist>fuel)
            return false;//无法移动，燃料不足
        else {//小车继续移动
           fuel-=dist;//剩余燃料
           //total= dist*fuelCost;
           x+=dx;
           y+=dy;
           //s=s+total;
           return true;
        }

   }
    public void show(){
        System.out.println("名称"+name);
        System.out.println("车宽"+width);
        System.out.println("车高"+height);
        System.out.println("车长"+length);
    }
    public double fuelCost(double dx,double dy){
        double dist=Math.sqrt(dx*dx+dy*dy);
        total= dist*fuelCost;
            return total;

    }

}
